﻿package mortal.game.view.collect
{
    import com.mui.containers.globalVariable.*;
    import com.mui.controls.*;
    import extend.language.*;
    import fl.data.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.platform.*;
    import mortal.game.view.yyZiZuan.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class LanderWindow extends BaseWindow
    {
        private var _downLoadButton:GLoadingButton;
        private var _getGiftBtn:GLoadingButton;
        private var _giftList:GTileList;
        protected const rewardItemCode:int = 120100422;
        private static var _instance:LanderWindow;

        public function LanderWindow(param1:ILayer = null)
        {
            super(param1);
            setSize(774, 480);
            title = Language.getString(21372);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.LanderWindowBg, 10, 38, this));
            this._downLoadButton = UIFactory.gLoadingButton(ResFileConst.platformDownLoadBtn, 330, 227, 130, 44, this);
            this._downLoadButton.configEventListener(MouseEvent.CLICK, this.onClickHandle);
            this._getGiftBtn = UIFactory.gLoadingButton(ResFileConst.platformGetGiftBtn1, 552, 360, 131, 39, this);
            this._getGiftBtn.configEventListener(MouseEvent.CLICK, this.onClickHandle);
            this._giftList = UIFactory.tileList(200 + 31 + 160, 300 + 51 - 8, 500, 80, this);
            this._giftList.columnWidth = 80;
            this._giftList.rowHeight = 80;
            this._giftList.setStyle("cellRenderer", PlatformDownLoadGiftCellRender);
            this._giftList.direction = GBoxDirection.HORIZONTAL;
            this._giftList.dataProvider = this.getGiftDataProviderByGiftItemCode(this.rewardItemCode);
            this._giftList.x = this._giftList.x - 0.5 * (this._giftList.dataProvider.length * this._giftList.columnWidth);
            this._giftList.drawNow();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            if (this._downLoadButton)
            {
                this._downLoadButton.dispose(param1);
                this._downLoadButton = null;
            }
            if (this._getGiftBtn)
            {
                this._getGiftBtn.dispose(param1);
                this._getGiftBtn = null;
            }
            if (this._giftList)
            {
                this._giftList.dispose(param1);
                this._giftList = null;
            }
            super.disposeImpl(param1);
            return;
        }// end function

        private function getGiftDataProviderByGiftItemCode(param1:int) : DataProvider
        {
            var _loc_5:Array = null;
            var _loc_6:ItemData = null;
            var _loc_9:YYZiZuanGiftDataGroup = null;
            var _loc_2:* = new DataProvider();
            var _loc_3:* = new ItemData(param1).itemInfo as ItemGiftBagInfo;
            var _loc_4:* = _loc_3.itemList1.split("&");
            var _loc_7:* = _loc_4.length;
            var _loc_8:int = 0;
            while (_loc_8 < _loc_4.length)
            {
                
                _loc_5 = _loc_4[_loc_8].split("#");
                _loc_9 = new YYZiZuanGiftDataGroup();
                _loc_9.itemCode = int(_loc_5[1]);
                _loc_9.itemAmount = _loc_5[2];
                _loc_9.isBind = true;
                _loc_2.addItem(_loc_9);
                _loc_8++;
            }
            return _loc_2;
        }// end function

        private function onClickHandle(event:MouseEvent) : void
        {
            switch(event.currentTarget)
            {
                case this._downLoadButton:
                {
                    DownLoadFileUtil.downloadToDesktop(ParamsConst.instance.downLoadLanderUrl, null);
                    break;
                }
                case this._getGiftBtn:
                {
                    if (ParamsConst.instance.isMiniCliet)
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.GetGameDownLoadReward));
                    }
                    else
                    {
                        MsgManager.showRollTipsMsg(Language.getString(21373));
                    }
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public static function get instance() : LanderWindow
        {
            if (!_instance)
            {
                _instance = new LanderWindow;
            }
            return _instance;
        }// end function

        public static function hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

    }
}
